#!/usr/bin/env python

import gtk
import gettext

gettext.install('blendIT','locale');

class signals:

   def __init__(self,blend):
      self.blend = blend;

   def on_response(self,widget,response,it):
      if response == gtk.RESPONSE_ACCEPT:
         # We have to do some checks on the data we receive from the user
         alias = str(it.aliasTextEntry.get_text().strip());
         jid = str(it.jidTextEntry.get_text().strip());
         message = it.inviteTextEntry.get_text();
         group = it.groupComboBox.get_active_text();
         
         # Fail on these         
         if alias == "":
            self.blend.gui.createErrorMessage(widget,
            _("You must enter an alias."));
            widget.run();
            return;
            
         if jid == "":
            self.blend.gui.createErrorMessage(widget,
            _("You must enter a number to add to MXit."));
            widget.run();
            return;
         
         # Now check to see if the alias is in use already
         pBuddy = self.blend.conn.roster.get_buddy(jid);
         
         if pBuddy is None and self.blend.conn.roster.find_buddy(alias) is None:
            # Add the contact
            widget.destroy();
            if group == "No Group":
                group = None;

            self.blend.conn.invite(jid,alias,group,message);
         else:
            self.blend.gui.createErrorMessage(widget,
            _("You already have a buddy with that alias added."));

            widget.run();
            return;            
      else:
         widget.destroy();